package com.leyou.search.controller;

import com.leyou.common.vo.PageResult;
import com.leyou.search.dto.GoodsDTO;
import com.leyou.search.dto.SearchRequest;
import com.leyou.search.entity.Goods;
import com.leyou.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
public class SearchController {
    @Autowired
    private SearchService searchService;

    //查询所有分页商品
    @PostMapping("/page")
    public ResponseEntity<PageResult<GoodsDTO>>  search(@RequestBody SearchRequest searchRequest){
        PageResult<GoodsDTO> goodsList = searchService.search(searchRequest);
        return ResponseEntity.ok(goodsList);
    }

    //查询过滤参数
    @PostMapping("/filter")
    public ResponseEntity<Map<String, List<?>>> filter(@RequestBody SearchRequest searchRequest){
        Map<String,List<?>> filters = searchService.filter(searchRequest);
        return ResponseEntity.ok(filters);
    }
}
